<?php

define('DOCUMENT_ROOT', dirname(dirname(__FILE__)));
define('INCPATH_LIB', DOCUMENT_ROOT . '/lib');
define('INCPATH_VIEWS', DOCUMENT_ROOT . '/views');
define('CANVAS_URL', 'https://joni2back.dyndns.org');
define('APP_NAMESPACE', 'dapadarnos');
define('APP_URL', 'https://apps.facebook.com/' . APP_NAMESPACE . '/');
define('HTTP_ASSETS', 'https://joni2back.dyndns.org' . '/assets');
define('HTTP_CSS', HTTP_ASSETS . '/css');
define('HTTP_JS', HTTP_ASSETS . '/js');

require_once INCPATH_LIB . '/src/facebook.php';
require_once INCPATH_LIB . '/helper.php';
require_once INCPATH_LIB . '/varien_object.php';
require_once INCPATH_LIB . '/data_session.php';
require_once INCPATH_LIB . '/mydatabase.php';
require_once INCPATH_LIB . '/dapadarse.php';

global $facebook, $user;

$app_id = '177803909789';
$app_secret = '89eefdca205b0a9960adb86d85a2f5d4';
$scope = 'email,publish_actions';

// Init the Facebook SDK
$facebook = new Facebook(array(
	'appId'  => $app_id,
	'secret' => $app_secret,
));

// Get the current user
$user = $facebook->getUser();

// If the user has not installed the app, redirect them to the Login Dialog
if (!$user) {
	$loginUrl = $facebook->getLoginUrl(array(
		'scope' => $scope,
		'redirect_uri' => APP_URL,
	));

	print('<script> top.location.href=\'' . $loginUrl . '\'</script>');
}
